/**
 * 用户服务
 * @TransactionAnnotation表示开启事务
 */

export default class DictionaryDetailService {


    /**
     * 注册用户
     * @param table                 指定表名称
     * @param dictionary                  用户属性
     * @returns {Promise<*>|void}
     *
     */

    addDictionaryDetailEntity(entity) {
        // return new Promise(async (resolve, reject) => {
        //     try {
        //         const sql =  "WHERE t_did = ? " + "ORDER BY t_createAt DESC"
        //         const rows = await this['session'].save('t_dictionary_detail',entity);
        //         const count = await this['session'].exeSQL("select count(*)  from t_dictionary_detail " + sql, [entity.t_did]);
        //         resolve({total: count[0]['count(*)'], records: rows});
        //     } catch (e) {
        //         reject(e)
        //     }
        // })
         return this['session'].save('t_dictionary_detail', entity);

    }

    /**
     * 保存
     * @param table
     * @param dictionaryName
     * @returns {*}
     */
    removeDictionaryDetailEntity(entity) {
        return this['session'].remove('t_dictionary_detail', entity);
    }

    /**
     * 更新
     * @param table
     * @param entity
     * @returns {*}
     */
    updateDictionaryDetailEntity(entity) {
        return this['session'].update('t_dictionary_detail', entity);
    }

    /**
     * 查询(分页)
     * @param table
     * @param start
     * @param size
     * @returns {*}
     */
    listDictionaryDetailEntities(start, size, keyWord,id) {
        return new Promise(async (resolve, reject) => {
            try {
                const sql = keyWord ? "WHERE `t_info` LIKE '%" + keyWord + "%' AND t_did = ? " : "WHERE t_did = ? " + "ORDER BY t_createAt DESC"
                const rows = await this['session'].query('t_dictionary_detail', sql, [id], start, size);
                const count = await this['session'].exeSQL("select count(*)  from t_dictionary_detail " + sql, [id]);
                resolve({total: count[0]['count(*)'], records: rows});
            } catch (e) {
                reject(e)
            }
        })
    }

    /**
     * 查询 不分页
     * @param did
     * @returns {Promise<unknown>}
     */
    listDictionaryDetailEntitiesNoPage(did) {
        const sql = "WHERE `t_did` = ? ORDER BY t_createAt DESC"
        return this['session'].query('t_dictionary_detail', sql, [did]);
    }


}


